package edu.sctu.xiangkun.day201506.day20150616.texttwo;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by user04 on 2015/6/17.
 */
public class HttpUtil {
public String getHttp(String path){
    int count = 0;
    try{
       URL url = new URL(path);

        try{
            InputStream inputStream = url.openStream();
          while((count = inputStream.read()) != -1){
              System.out.print((char) count);
          }
        }catch(IOException ex){
            ex.printStackTrace();
        }
    }catch(MalformedURLException ex){
        ex.printStackTrace();
    }

    return path;
}

    public void getHttpOne(String path){
        int count = 0;
        try{
            URL url = new URL(path);
            byte[] buffer = new byte[1024];

            try{
                InputStream inputStream = url.openStream();
                while((count = inputStream.read(buffer)) != -1){
                    System.out.println(new String(buffer,0,count,"gb2312"));
                }
            }catch(IOException ex){
                ex.printStackTrace();
            }
        }catch(MalformedURLException ex){
            ex.printStackTrace();
        }

    }
}
